package com.concerneyes.mine.Task;

import android.content.Context;

import com.concerneyes.CEApp;
import com.concerneyes.R;

import http.HttpAsyncTask;
import http.JsonMap;
import http.Url;
import util.ToastHelper;

/**
 * 产品相关网路请求
 */
public class ExtensionImpl {
	private Context context;
	private ExtensionListener listener;

	public ExtensionImpl(ExtensionListener listener) {
		this.listener = listener;
		this.context = CEApp.getInstance();
	}

	/**
	 * 产品分类列表
	 */
	public void extensionImpl(String adress) {


		HttpAsyncTask http = new HttpAsyncTask() {

			@Override
			public void onStart(String taskId) {
			}

			@Override
			public void onFinish(String taskId, String response) {
				JsonMap data = JsonMap.parseJson(response);
				if (data == null) {
					ToastHelper.getInstance()._toast( R.string.network_error_tip);
					if (listener != null) {
						listener.onExtensionFail();
					}
					return;
				}

				if (data.getInt("code") == 200) {
					if (listener != null) {
						listener.onExtensionSuccess(data.getListMap("data"));
					}
				} else {
					ToastHelper.getInstance()._toast(data.getString("msg"));
					if (listener != null) {
						listener.onExtensionFail();
					}
				}
			}
		};
		http.setDebug(true);
		http.excute(Url.BaseUrl + adress, null, "POST");
	}




}
